<template>
  <div class="mainbox">
    <el-input
      style="width: 20%; float: right"
      v-model="searchKeyword"
      placeholder="请输入表单名称进行搜索"
      clearable
      @input="handleSearch"
    ></el-input>
    <el-table
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      style="width: 100%; margin-top: 20px"
    >
      <el-table-column prop="formName" label="表单名称" />
      <el-table-column prop="formType" label="表单标识" />
      <el-table-column prop="formOrigin" label="表单来源" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            size="small"
            type="primary"
            @click="handleDesign(scope.$index, scope.row)"
          >
            设计
          </el-button>
          <el-button
            size="small"
            @click="handelPreview(scope.$index, scope.row)"
          >
            预览
          </el-button>
          <el-button size="small" @click="handelUse(scope.$index, scope.row)">
            使用
          </el-button>
          <el-button
            size="small"
            @click="handelPublish(scope.$index, scope.row)"
          >
            发布
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 20px; float: right"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20, 50]"
      :page-size="pageSize"
      :total="tableData.length"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script setup lang="ts">
import router from "@/router";
import { ref, reactive, toRefs, onMounted, computed } from "vue";
// interface User {
//   formName: string;
//   formType: string;
//   formOrigin: string;
// }
const tableData11 = ref([
  {
    id: 1,
    formName: "表单1",
    formType: "form1",
    formOrigin: "用户",
  },
  {
    id: 2,
    formName: "表单2",
    formType: "form2",
    formOrigin: "管理员",
  },
  {
    id: 3,
    formName: "表单3",
    formType: "form3",
    formOrigin: "测试",
  },
  {
    id: 4,
    formName: "表单4",
    formType: "form4",
    formOrigin: "运维",
  },
  {
    id: 5,
    formName: "表单5",
    formType: "form5",
    formOrigin: "运维",
  },
  {
    id: 6,
    formName: "表单6",
    formType: "form6",
    formOrigin: "产品",
  },
  {
    id: 7,
    formName: "表单7",
    formType: "form7",
    formOrigin: "开发者",
  },
  {
    id: 8,
    formName: "表单8",
    formType: "form8",
    formOrigin: "管理员",
  },
  {
    id: 9,
    formName: "表单9",
    formType: "form9",
    formOrigin: "测试",
  },
  {
    id: 10,
    formName: "表单10",
    formType: "form10",
    formOrigin: "用户",
  },
  {
    id: 11,
    formName: "表单11",
    formType: "form11",
    formOrigin: "测试",
  },
  {
    id: 12,
    formName: "表单12",
    formType: "form12",
    formOrigin: "开发者",
  },
  {
    id: 13,
    formName: "表单13",
    formType: "form13",
    formOrigin: "用户",
  },
]);
const pageSize = ref(20);
const currentPage = ref(1);
const searchKeyword = ref("");

//可以通过计算属性返回模糊匹配的表格数据
// 模糊搜索处理
const tableData = computed(() => {
  return tableData11.value.filter((item) => {
    // 这里可以根据需要搜索的字段进行逻辑判断
    return item.formName.includes(searchKeyword.value);
  });
});

function handleSearch() {
  // 这里可以添加重新加载数据的逻辑，如发起API请求获取数据
}
function handleSizeChange(val) {
  pageSize.value = val;
}
function handleCurrentChange(val) {
  currentPage.value = val;
}
//去编辑器
function handleDesign(index, row) {
  router.push({
    path: "/formDesigner",
    query: {
      id:row.id
    }
  });
}
//去预览
function handelPreview(index, row) {
  router.push({
    path: "/previewIframe",
    query: {
      id:row.id
    }
  });
}
//去使用
function handelUse(index, row) {}
//去发布
function handelPublish(index, row) {}
// onMounted(() => {
//   getTableList();
// });
// function getTableList() {
//    tableData = [
//     {
//       formName: "2016-05-03",
//       formType: "Tom",
//       formOrigin: "No. 189, Grove St, Los Angeles",
//     },
//     {
//       formName: "2016-05-02",
//       formType: "Tom",
//       formOrigin: "No. 189, Grove St, Los Angeles",
//     },
//     {
//       formName: "2016-05-04",
//       formType: "Tom",
//       formOrigin: "No. 189, Grove St, Los Angeles",
//     },
//     {
//       formName: "2016-05-01",
//       formType: "Tom",
//       formOrigin: "No. 189, Grove St, Los Angeles",
//     },
//   ];
// }
</script>
<style scoped lang="scss">
.mainbox {
  padding: 20px;
}
</style>
